package com.java3_9;

public class DishTake implements Runnable {
    private TotalDish dish;

    public DishTake(){

    }
    public DishTake(TotalDish dish) {
        this.dish = dish;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (TotalDish.class) {
                while (dish.getDish()<=0){
                    try {
                        TotalDish.class.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                dish.delDish();
                System.out.println(Thread.currentThread().getName() + "  将菜端走了一份" + "现在一共有" + dish.getDish() + "份菜");
                TotalDish.class.notifyAll();
            }
        }
    }
}
